package com.well.register.console.util;

import lombok.Data;

/**
 * <p>
 * Rpc Response Model
 * </p>
 *
 * @author weedo
 * @since 2022/7/30
 */
@Data
public class RpcResponse<T> {
    private Integer code;
    private T data;
    private String msg;

    public RpcResponse() {
    }

    public RpcResponse(T obj) {
        this.code = 200;
        this.data = obj;
        this.msg = "success";
    }

    public RpcResponse(Integer code, T obj, String msg) {
        this.code = code;
        this.data = obj;
        this.msg = msg;
    }

    public static RpcResponse<Object> ok() {
        return new RpcResponse<>(200, null, "OK");
    }

    public static RpcResponse<Object> ok(Object obj) {
        return new RpcResponse<>(200, obj, "OK");
    }

    public static RpcResponse<Object> fail(CodeInfo codeInfo) {
        return new RpcResponse<>(codeInfo.code, null, codeInfo.msg);
    }

    public static RpcResponse<Object> fail(int code, String msg) {
        return new RpcResponse<>(code, null, msg);
    }
}
